#ifndef __JUDGE__
#define __JUDGE__
#include "chessBoard.h"
#include "player.h"
class Judge{
	public:
	bool isWin(Player *player){
		bool ok=isHorizontal(player->getColor());
		if(ok){
			return true;
		}
		ok=isvertical(player->getColor());
		if(ok){
			return true;
		}
		ok=isUpHill(player->getColor());
		if(ok){
			return true;
		}
		ok=isDownHill(player->getColor());
		if(ok){
			return true;
		}
		return false;
	}
	bool isHorizontal(const string &color){
		int count=0;
		ChessBoard *chessBoard=ChessBoard::getChessBoard();
		int line=chessBoard->getLine();
		int col=chessBoard->getCol();
		for(int i=0;i<5;i++){
			int ret=chessBoard->getCursorval(color,line,col+i);
			if(ret==1){
				count++;
			}else{
				break;
			}
		}
		if(count >= 5){
			return true;
		}
		for(int i=0;i<5;i++){
			int ret=chessBoard->getCursorval(color,line,col-i);
			if(ret==1){
				count++;
			}else{
				break;
			}
		}

		if(count-1 >= 5){
			return true;
		}
		return false;
	}
	bool isvertical(const string &color){
		ChessBoard *chessBoard=ChessBoard::getChessBoard();
		int line=chessBoard->getLine();
		int col=chessBoard->getCol();
		int count=0;
		for(int i=0;i<5;i++){
			int ret=chessBoard->getCursorval(color,line-i,col);
			if(ret==1){
				count++;
			}else{
				break;
			}
		}
		if(count>=5){
			return true;
		}
		for(int i=0;i<5;i++){
			int ret=chessBoard->getCursorval(color,line+i,col);
			if(ret==1){
				count++;
			}else{
				break;
			}
		}
		if(count-1>=5){
			return true;
		}
		return false;
	}
	bool isUpHill(const string &color){
		ChessBoard *chessBoard=ChessBoard::getChessBoard();
		int line=chessBoard->getLine();
		int col=chessBoard->getCol();
		int count=0;
		for(int i=0;i<5;i++){
			int ret=chessBoard->getCursorval(color,line-i,col+i);
			if(ret==1){
				count++;
			}else{
				break;
			}
		}
		if(count>=5){
			return true;
		}
		for(int i=0;i<5;i++){
			int ret=chessBoard->getCursorval(color,line+i,col-i);
			if(ret==1){
				count++;
			}else{
				break;
			}
		}
		if(count-1>=5){
			return true;
		}
		return false;

	}
	bool isDownHill(const string &color){
		ChessBoard *chessBoard=ChessBoard::getChessBoard();
		int line=chessBoard->getLine();
		int col=chessBoard->getCol();
		int count=0;
		for(int i=0;i<5;i++){
			int ret=chessBoard->getCursorval(color,line-i,col-i);
			if(ret==1){
				count++;
			}else{
				break;
			}
		}
		if(count>=5){
			return true;
		}
		for(int i=0;i<5;i++){
			int ret=chessBoard->getCursorval(color,line+i,col+i);
			if(ret==1){
				count++;
			}else{
				break;
			}
		}
		if(count-1>=5){
			return true;
		}
		return false;

	}
};
#endif
